// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of HTMLDOMTranslator
//
// HTMLDOMTranslator is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// HTMLDOMTranslator is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with DOM3ImplReg. If not, see <http://www.gnu.org/licenses/>.

//	Purpose: definition of the CHTMLDOMTranslator class
#pragma once

#include <wtypes.h>

//Forward Declarations of MSXML interfaces used here.
struct IXMLDOMNode;
struct IXMLDOMDocument;
struct IXMLDOMElement;

//Forward Declarations of MSHTML interfaces used here.
struct IHTMLDOMNode;

//<summary>
//	class for translating MSHTML HTML DOM Nodes into MSXML XML DOM Nodes.
//</summary>
//<remarks>
//	No Default Constructor, must supply a CLSID for creating the MSXML document
//</remarks>
class CHTMLDOMTranslator
{
public:
	//<summary>
	// constructor.
	//</summary>
	//<parameter name-"clsid">
	//	clsid of a class implementing IXMLDOMDocument to be used as a factory
	//	for translating HTML nodes to xml nodes.
	//</parameter>
	explicit CHTMLDOMTranslator(const CLSID &clsid);
	//<summary>destructor</summary>
	~CHTMLDOMTranslator(void);
	// <summary>Translates the HTMLDOMNode  pHTML into an XML DOM Node ppXML</summary>
	//<returns>
	//	E_NOINTERFACE if the object created by the argument supplied 
	//	to the constructor does not support MSXML2::IXMLDOMDocument.
	//	<br /> Otherwise some other error or success code.
	//</returns>
	HRESULT cloneNode(IHTMLDOMNode * pHTML, IXMLDOMNode ** ppXML,const bool bDeep) const;
	// <summary>
	//	Translates the HTMLDOMNode  pHTML into an XML DOM Node,
	//	and returns it as the documentElement of ppXML
	//</summary>
	//<returns>
	//	E_NOINTERFACE if the object created by the argument supplied 
	//	to the constructor does not support MSXML2::IXMLDOMDocument.
	//	<br /> Otherwise some other error or success code.
	//</returns>
	HRESULT cloneNode(IHTMLDOMNode * pHTML, IXMLDOMDocument ** ppXML,const bool bDeep) const;
private:
	//<summary>
	// Translates an HTML Node known to be an element into an xml element
	//</summary>
	//<returns>
	//	E_INVALIDARG if pHTML is not an element
	//</returns>
	HRESULT translateElement(IXMLDOMDocument * pDoc,IHTMLDOMNode * pHTML, IXMLDOMNode ** ppXML, const bool bDeep) const;
	//<summary>
	// Translates an HTML Node known to be a text node into an xml text node
	//</summary>
	//<returns>
	//	E_INVALIDARG if pHTML is not text
	//</returns>
	HRESULT translateText(IXMLDOMDocument * pDoc,IHTMLDOMNode * pHTML, IXMLDOMNode ** ppXML) const;
	//<summary>
	// Translates an HTML Node of unknown type into an appropriate XML node
	//</summary>
	//<returns>
	//	S_OK if successful, 
	//	S_FALSE if the node was understood, but not translated (e.g. comment).
	//	E_FAIL otherwise
	//</returns>
	HRESULT internalTranslateHTMLToXML(IXMLDOMDocument * pDoc,IHTMLDOMNode * pHTML, IXMLDOMNode ** ppXML, const bool bDeep) const;
	//<summary>
	// Copies the attributes from an HTML node known to be an element, into an xml element
	//</summary>
	void copyAttributes(IHTMLDOMNode * pColl,IXMLDOMElement * pEl) const;
	//<summary>
	// Copies the children of a given HTML node into an XML Node, using pDoc as a factory.
	//</summary>
	HRESULT copyChildren(IXMLDOMDocument * pDoc,IHTMLDOMNode * pHTML,IXMLDOMNode * pEl) const;
	//<summary>
	//	clsid which is used to create an object supporting the interface 
	//	MSXML2::IXMLDOMDocument, which can be used as a factory.
	//</summary>
	const CLSID  m_clsid;
};
